package com.xuan.xwaterfall.component;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class MyImageView extends ImageView {

	private String TAG = "MyImageView";
	private String name;
	private int state; //用来检验onResumeView和onRecycleView交替执行,且先onResumeView再有onRecycleView
	
	public MyImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		 this.setOnClickListener(onclick);//XWaterFall不会影响上层View的OnClickListener等操作
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void setImageBitmap(Bitmap bm) {
		// TODO Auto-generated method stub
		// Log.v(name, "setImageBitmap");
		super.setImageBitmap(bm);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		// Log.v(name, "onDraw :" + drawNum++ );
		try {
			super.onDraw(canvas);
		} catch (Exception e) {
			e.printStackTrace();
			Log.v(TAG, name);
		}
	}

	public void recycle(){
		Log.v(TAG, "XX回收" + name);
		state--;
		if(state!= 0){
			Log.v(TAG, "XX错误: state:" + state);
		}
	}
	
	public void resume(){
		Log.v(TAG, "XX恢复" + name);
		state++;
		if(state != 1){
			Log.v(TAG, "XX错误: state:" + state);
		}
	}
	
	OnClickListener onclick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Log.v(TAG, "OnClickListener");
		}
	};

}
